import java.util.*;
import java.lang.*;
import java.io.*;

public class GraphTest1
 {
  public static void main(String args[])
  {
	try
	 {
	 	Graph<Integer> graph1 = new Graph<Integer>();
	 
		FileInputStream fstream = new FileInputStream(args[0]);
  		BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
		boolean undirected = true;

  		String strLine;
		int numberOfVertices = 0;
		int numberOfEdges = 0;
		
		String strLine1 = br.readLine();
		if(strLine1.equals("D"))
		{
		    undirected = false;
		}
		HashSet<Vertex> vertexSet = new HashSet<Vertex>();
		HashSet<Edge> edgeSet = new HashSet<Edge>();
		Hashtable<Integer, Vertex> vertexhash = new Hashtable<Integer, Vertex>();
					
			strLine = br.readLine();
		
			String a[] = strLine.split(" ");
			numberOfVertices = Integer.parseInt(a[0]);
			numberOfEdges =  Integer.parseInt(a[1]);
			System.out.println("NO OF VERTECES AND EDGES ARE:"); 
			System.out.println(numberOfVertices+"\t"+numberOfEdges);
					
			for(int k=1;k<=numberOfVertices;k++)
			{
				Vertex<Integer,Integer> vertex1 = new Vertex<Integer,Integer>(k,0);
				System.out.println("Inserted Vertex:" +k);
				vertexhash.put(k, vertex1);
				vertexSet.add(vertex1);
								
			}
			
			while((strLine = br.readLine()) != null)
			{
				String a1[] = strLine.split(" ");
				Integer leftV = Integer.parseInt(a1[0]);
				Integer rightV =  Integer.parseInt(a1[1]);
				Double w = Double.parseDouble(a1[2]);
				
				Vertex<Integer,Integer> vertex1 = vertexhash.get(leftV);
				Vertex<Integer,Integer> vertex2 = vertexhash.get(rightV);
											
				Edge<Integer> edge1 = new Edge<Integer>(vertex1, vertex2, w);
				System.out.println("Inserted edge: (" +vertex1+", "+ vertex2+")");
				
				edgeSet.add(edge1);
							
				if(undirected == true)
				{
						
					Edge<Integer> edge2 = new Edge<Integer>(vertex2, vertex1, w);
					System.out.println("Inserted edge: (" +vertex2+", "+ vertex1+")");
					edgeSet.add(edge2);
				}
		
			}	
			graph1 = new Graph<Integer>(vertexSet, edgeSet);		
			
			System.out.println("Enter the Edge (u, v) you want locate");
			Scanner sc = new Scanner(System.in);
     			int v1 = sc.nextInt();
			int v2 = sc.nextInt();
						
			boolean status = graph1.isEdgeInTheGraph(graph1.getVertexNode(v1), graph1.getVertexNode(v2));
			System.out.println(status);
			
		 
		
		fstream.close();	
	}	
	catch(Exception e)
	{
		e.printStackTrace();
	}
  }
}
			
